<?php 
	Class social_networks_m extends CI_Model
	{

		public function addSocialNetwork()
	    {	
			$data = array(
							'GMRS_CODE' => $_POST['GMRS_CODE'],
							'GMET_CODE' =>  $_POST['GMET_CODE'],
							'GMERS_LINK' =>  $_POST['GMERS_LINK'],
							'GMERS_STATUT' => "actif" 
    					);
			$this->db->insert('GM_etudiant_reseau_social', $data);
		}

		public function getSocialNetworks()
		{
			$social_networks = $this->db->select('*')->from('GMReseauxSociaux')->get();
			return $social_networks->result();
		}

		public function getAllSocialNetworksById($id)
		{
			$social_networks = $this->db->select('GM_etudiant_reseau_social.GMRS_CODE, GM_etudiant_reseau_social.GMERS_LINK, GM_etudiant_reseau_social.GMERS_STATUT, GMReseauxSociaux.GMRS_NOM, GMReseauxSociaux.GMRS_LOGO')->from('GM_etudiant_reseau_social')->join('GMReseauxSociaux','GM_etudiant_reseau_social.GMRS_CODE = GMReseauxSociaux.GMRS_CODE')->where('GM_etudiant_reseau_social.GMET_CODE', $id)->get();
			return $social_networks->result();
		}

		public function deleteSocialNetwork()
	    {	
			$where = array(
							'GMRS_CODE' => $_POST['GMRS_CODE'],
							'GMET_CODE' => $_POST['GMET_CODE']
    					);
			$this->db->delete('GM_etudiant_reseau_social', $where);
		}

		public function desactivateSocialNetwork()
		{	
			$where = array(
							'GMRS_CODE' => $_POST['GMRS_CODE'],
							'GMET_CODE' => $_POST['GMET_CODE'],
							'GMERS_STATUT' => 'actif'
						);
			$data = array(
    						'GMERS_STATUT' => 'desactive'
						);
			$this->db->where($where)->update('GM_etudiant_reseau_social', $data);
		}

		public function activateSocialNetwork()
		{	
			$where = array(
							'GMRS_CODE' => $_POST['GMRS_CODE'],
							'GMET_CODE' => $_POST['GMET_CODE'],
							'GMERS_STATUT' => 'desactive'
						);
			$data = array(
    						'GMERS_STATUT' => 'actif'
						);
			$this->db->where($where)->update('GM_etudiant_reseau_social', $data);
		}

		public function desactivateAllSocialNetworksById()
		{	
			$where = array(
							'GMET_CODE' => $_POST['GMET_CODE'],
							'GMERS_STATUT' => 'actif'
						);
			$data = array(
    						'GMERS_STATUT' => 'desactive'
						);
			$this->db->where($where)->update('GM_etudiant_reseau_social', $data);
		}

		public function activateAllSocialNetworksById()
		{	
			$where = array(
							'GMET_CODE' => $_POST['GMET_CODE'],
							'GMERS_STATUT' => 'desactive'
						);
			$data = array(
    						'GMERS_STATUT' => 'actif'
						);
			$this->db->where($where)->update('GM_etudiant_reseau_social', $data);
		}

	}
?>
